package io.xxx.omni.mdc.model

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import org.apache.ibatis.annotations.Mapper
import org.springframework.stereotype.Repository
import java.time.LocalDateTime

/**
 * 开发者信息
 */
data class Authorization(
    @TableId
    var id: Int?,
    var pid: String?,
    var sid: String?,
    var data: String?,
    var enabled: Boolean?,
    var created: LocalDateTime?,
    var modified: LocalDateTime?,
)

@Mapper
@Repository
interface AuthorizationMapper : BaseMapper<Authorization>

/**
 * 平台（外部）
 */
data class Platform(
    @TableId
    var id: String?,
    var name: String?,
    var enabled: Boolean?,
    var created: LocalDateTime?,
    var modified: LocalDateTime?,

    @TableField(exist = false)
    var authorizations: List<Authorization> = emptyList(),
) {
    @Suppress("unused")
    constructor() : this(null, null, null, null, null)
}

@Mapper
@Repository
interface PlatformMapper : BaseMapper<Platform>

/**
 * 店铺（外部）
 */
data class Store(
    @TableId(type = IdType.AUTO)
    var id: String?,
    var pid: String?,
    /**
     * 平台商家id
     */
    var oid: String?,
    var name: String?,
    var oname: String?,
    var enabled: Boolean?,
    var created: LocalDateTime?,
    var modified: LocalDateTime?,

    @TableField(exist = false)
    var platform: Platform?,
    @TableField(exist = false)
    var authorization: Authorization?,
) {
    @Suppress("unused")
    constructor() : this(
        null, null, null, null, null,
        null, null, null, null, null
    )
}

@Mapper
interface StoreMapper : BaseMapper<Store>
